﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Mvc;

namespace skhukb.Util
{
    public class CssLink
    {
        private static string KEY = "CssLink";
        private static MvcHtmlString EMPTY = MvcHtmlString.Create(String.Empty);

        public static void Add(string url)
        {
            var list = (List<string>)HttpContext.Current.Items[KEY];
            if (list == null) 
                HttpContext.Current.Items[KEY] = list = new List<string>();
            list.Add(url);
        }

        public static MvcHtmlString Render()
        {
            var list = (List<string>)HttpContext.Current.Items[KEY];
            if (list == null) return EMPTY;

            var result = new StringBuilder();
            foreach (var url in list) {
                result.Append("<link href='");
                result.Append(System.Web.VirtualPathUtility.ToAbsolute(url));
                result.Append("' rel='stylesheet' media='screen'>");
            }
            return MvcHtmlString.Create(result.ToString());
        }
    }
}